package com.wenx.ftpcamel;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.model.ModelCamelContext;

/**
 * 本地路径下文件传送经过activemq
 */
public class SftpDemo {
    public static void main(String[] args) throws Exception {
        ModelCamelContext camelContext = new DefaultCamelContext();
        camelContext.start();
        camelContext.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("sftp://10.10.3.162:49622?username=root&password=bigdata*123" +
                        "&delete=false" +
                        "&move=${date:now:yyyyMMdd}/${file:name}" +
                        "&moveFailed=./error")
                        .process(new Processor() {
                            public void process(Exchange exchange) throws Exception {
                                System.out.println("*******************");
                                System.out.println("文件名 ： " + exchange.getIn().getHeader(Exchange.FILE_NAME));
                                System.out.println("绝对路径 ： " + exchange.getIn().getHeader("CamelFileAbsolutePath"));
                                System.out.println("最后修改时间 ： " + exchange.getIn().getHeader("CamelFileLastModified"));
                                System.out.println("文件大小： " + exchange.getIn().getHeader("CamelFileLength"));
                            }
                        })
                        .to("file:D://test");
            }
        });
        synchronized (SftpDemo.class) {
            SftpDemo.class.wait();
        }
    }
}
